<template>
	<w-container>
		<w-navbar bgColor="#fff" title="公告">
			<template #center>
				<w-tabs :tabList="tabList" @change="changeTab"></w-tabs>
			</template>
		</w-navbar>
		<NoticeList ref='notice-list' v-show="tabIndex==0"></NoticeList>
		<NewList ref='news' v-show="tabIndex==1"></NewList>
		<WallList ref="wall" v-show="tabIndex==2"></WallList>
		<w-modal v-model="code_url_show" title="Wxpush推送" :showButton="false" :closeOnClickOverlay='false'>
			<image mode="aspectFit" style="width: 100%;" :src="code_url"></image>
			<w-button class="mt-32" shape="circle" @click='code_url_show=false'>我知道了</w-button>
		</w-modal>
	</w-container>
</template>

<script>
	import NoticeList from './components/notice-list.vue'
	import NewList from './components/new-list.vue'
	import WallList from './components/wall-list.vue'
	import {
		OriginOssUrl
	} from '@/config/index.js'
	import {
		bindwx_pusercode
	} from "@/api/notice/index.js"
	export default {
		components: {
			NoticeList,
			NewList,
			WallList
		},
		props: {
			lineBg: {
				type: String,
				default: () => {
					let imgUrl = `${OriginOssUrl}/static/bg/vector.png`
					return `url(${imgUrl}) 100% 100%`
				}
			},
		},
		data() {
			return {
				tabList: [{
						name: '官方公告',
					},
					{
						name: '新闻中心',
					},
					// {
					// 	name: '辟谣曝光',
					// }
				],
				tabIndex: 0,
				refList: ['notice-list', 'news', 'wall'],
				code_url_show: false,
				code_url: '',
			};
		},
		computed: {
			currentRef() {
				return this.$refs[this.refList[this.tabIndex]]
			}
		},
		onShow() {
			let index = uni.getStorageSync('notice');
			if (String(index)) {
				this.$nextTick(() => {
					this.$refs['notice-list'].changeClass({
						index,
						refresh: true
					})
				})
				uni.removeStorageSync('notice')
			} else {
				this.$nextTick(() => {
					this.currentRef.refresh();
				})
			}

		},
		onLoad() {
			this.changeTab({
				index: 0,
				refresh: true
			})
		},
		onReachBottom() {
			this.currentRef.loadMore();
		},
		onPullDownRefresh() {
			this.currentRef.refresh();
		},
		onShow() {
			// let isApp = uni.getStorageSync('app')
			// if (isApp) {
			// 	uni.hideTabBar()
			// } else {
			// 	uni.showTabBar()
			// }
		},

		methods: {
			changeTab({
				index
			}) {
				this.tabIndex = index;

				this.$nextTick(() => {
					this.currentRef.init()
				})
			},
			/**
			 * 获取是否绑定微信
			 */
			get_bindwx_pusercode() {
				if (!this.isLogin) {
					uni.$emit('showLogin')
					return;
				}
				if (this.code_url) return this.code_url_show = true
				bindwx_pusercode().then(res => {
					// 处理返回结果...
					this.code_url = res.data.code_url
					this.code_url_show = true
				}).catch(err => {})

			},
		},

	}
</script>

<style lang="scss" scoped>
	.market-tab {
		font-size: 32rpx;
		color: #CCCCCC;
		// margin-left: 48rpx;
		

		view {
			padding-top: 10rpx;
		}

		.active {
			color: #fff;
			font-size: 36rpx;
			background: url($IMG_URL + '/static/icon/market-tab-bg.png');
			background-size: contain;
			background-repeat: no-repeat;
			background-position: center;
		}
	}

	.search_box {
		width: 100%;
		height: 80rpx;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		background: rgba(0, 0, 0, 0.05);
	}

	.gg-dingyue {
		background-color: #D42F2F;
		font-size: 24rpx;
		color: #FFFFFF;
		margin-left: 30rpx;
		border-radius: 16rpx;
	}
</style>